﻿using System;
using System.Security.Principal;
using Bricks.Security;
using Microsoft.Practices.EnterpriseLibrary.Security;

namespace Bricks.EnterpriseLibrary.Security
{

    /// <summary>
    /// 
    /// </summary>
    public class AuthorizationProviderFacade : AuthorizationFacadeBase<IAuthorizationProvider>, IAuthorizationProviderFacade
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="authorizationProvider"></param>
        public AuthorizationProviderFacade(IAuthorizationProvider authorizationProvider) :
            base(() => authorizationProvider)
        {
            if (authorizationProvider == null)
            {
                throw new ArgumentNullException("authorizationProvider");
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="principal"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public override bool Authorize(IPrincipal principal, string key)
        {
            return Execute(authorizationProvider => authorizationProvider.Authorize(principal, key));
        }
    }
}
